﻿@using Blazor.Diagrams.Components.Renderers;
@using OnWork.DataCenter.BLL.DataCenter;
@inherits ComponentBaseDataCenter
<div class="standard-node @(Node.Selected ? " selected" : "")" style="width: 250px;">
    <Card >
        <BodyTemplate >
            <h5>@Node.Name</h5>
            <div class="row g-3">
                <div class="col-auto col-form-label">
                    <span>输入类型</span>
                </div>
                <div class="col-8">
                    <Display Value="@Node.DataType" />
                </div>
            </div>
            <div class="row g-3">
                <div class="col-auto col-form-label">
                    <span> 输出类型</span>
                </div>
                <div class="col-8">
                    <Display Value="@Node.OutType" />
                </div>
            </div>
            <div class="row g-3">
                <div class="col-12">
                    <div class="btn-group" role="group">
                        <Button Color="Color.Primary" Size="Size.Small" OnClick="@(async x=>{await EditModel(@Node);})">配置编辑</Button>
                        @*<Button Color="Color.Success" Size="Size.Small" >Button two</Button>*@
                    </div>
                </div>
            </div>
        </BodyTemplate>
    </Card>
    @foreach (var port in Node.Ports)
    {
        <PortRenderer Port="port" Class="default"></PortRenderer>
    }
</div>

@code {
    [Parameter]
    public StandardNode Node { get; set; }


    /// <summary>
    /// 依赖注入 数据标准对象
    /// </summary>
    [Inject]
    protected DataStandardBLL dsBLL { get; set; }


    /// <summary>
    ///  编辑模型
    /// </summary>
    /// <param name="node"></param>
    /// <returns></returns>
    private async Task EditModel(StandardNode node)
    {
        var config = await dsBLL.Queryable().Where(x => x.ID == node.ID).FirstAsync();


        var result = await DialogService.ShowModal<DataStandardConfigEditView>(new ResultDialogOption()
            {
                Title = "流程编辑",
                ButtonNoText = "取消",
                ButtonYesText = "保存",
                ComponentParameters = new Dictionary<string, object>
                {
                    [nameof(DataStandardConfigEditView.Config)] = config.Adapt<DataStandardConfigVO>(),
                    [nameof(DataStandardConfigEditView.OnCloseResult)] = new Action<DataStandardConfigVO>(async x =>
                    {
                        //只保存数据示例和配置
                        config.DataDemo = x.DataDemo;
                        config.StandardConfig = x.StandardConfig;
                        var r = await dsBLL.UpdateDataAsync(config);
                        await ShowSqlReturnMsg(r);
                    }),
                  
                }
            });
    }
}
